package com.lzs.adx.web.modules.job.task;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.lzs.adx.web.modules.job.dto.JobTaskParams;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TbCpaTask implements ITask{
    @Override
    public void run(String params) {
       if(StringUtils.isBlank(params)){
           log.info("未配置接口信息");
       }
        JobTaskParams jobTaskParams = JSONObject.parseObject(params, JobTaskParams.class);
        if(jobTaskParams.getMethod().equals("post")){
            String post = HttpUtil.post(jobTaskParams.getUrl(), jobTaskParams.getParams());
            log.info("post请求返回结果："+post);
        }else{
            JSONObject jsonObject = JSONObject.parseObject(jobTaskParams.getParams());
            String get = HttpUtil.get(jobTaskParams.getUrl(), jsonObject);
            log.info("get请求返回结果："+get);
        }

    }
}
